package com.zr.dao.impl;



import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.zr.dao.AddCarStateDao;
import com.zr.model.Car;
import com.zr.model.Point;
import com.zr.model.State;
import com.zr.model.Status;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;



@Repository( "addCarDao")
public class AddCarStateDaoImpl<T> extends BaseDaOImpl<T> implements AddCarStateDao {

	@Override
	public JSONArray findstates() {
	JSONArray j= new JSONArray();
	String hql = " from State ";
	Query query = this.getCurrentSession().createQuery(hql);
	List <State>  fs = query.list();
	for (State func : fs) {
		JSONObject j1 = new JSONObject();
		j1.put("id", func.getSid());
		j1.put("text",func.getSname());	
		j.add(j1);		
	}
		return j;
	}

	@Override
	public JSONArray findpositions() {
		JSONArray j= new JSONArray();
		String hql = " from Point";
		Query query = this.getCurrentSession().createQuery(hql);
		List <Point>  fs = query.list();
		for (Point func : fs) {
			JSONObject j1 = new JSONObject();
			j1.put("id", func.getPid());
			j1.put("text",func.getPname());	
			j.add(j1);		
		}
		return j;
	}

	@Override
	public JSONArray findPlates() {
		JSONArray j= new JSONArray();
		String hql = " from Car where state='空闲'";
		Query query = this.getCurrentSession().createQuery(hql);
		List <Car>  fs = query.list();
		for (Car func : fs) {
			JSONObject j1 = new JSONObject();
			j1.put("id", func.getCid());
			j1.put("text",func.getPlate());	
			j.add(j1);		
		}
		return j;
	}

	@Override
	public JSONArray findOrderstatuss() {
		JSONArray j= new JSONArray();
		String hql = " from Status where status='运输中'";
		Query query = this.getCurrentSession().createQuery(hql);
		List <Status>  fs = query.list();
		for (Status func : fs) {
			JSONObject j1 = new JSONObject();
			j1.put("id", func.getId());
			j1.put("text",func.getStatus());	
			j.add(j1);		
		}
		return j;
	}

}
